package com.xiaoxin.nmzp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;



import com.ruoyi.system.service.ISysUserService;
import com.xiaoxin.nmzp.domain.NmzpJobResume;
import com.xiaoxin.nmzp.domain.NmzpResume;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.xiaoxin.nmzp.domain.NmzpJob;
import com.xiaoxin.nmzp.service.INmzpJobService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职位管理Controller
 *
 * @author xiaoxin
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/nmzp/job")
public class NmzpJobController extends BaseController {
    @Autowired
    private INmzpJobService nmzpJobService;

    @Autowired
    private ISysUserService userService;

    /**
     * 查询职位管理列表
     */
    @PreAuthorize("@ss.hasPermi('nmzp:job:list')")
    @GetMapping("/list")
    public TableDataInfo list(NmzpJob nmzpJob) {
        startPage();

        List<NmzpJob> list = nmzpJobService.selectNmzpJobList(nmzpJob);
        return getDataTable(list);
    }

    /**
     * 导出职位管理列表
     */
    @PreAuthorize("@ss.hasPermi('nmzp:job:export')")
    @Log(title = "职位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NmzpJob nmzpJob) {
        List<NmzpJob> list = nmzpJobService.selectNmzpJobList(nmzpJob);
        ExcelUtil<NmzpJob> util = new ExcelUtil<NmzpJob>(NmzpJob.class);
        util.exportExcel(response, list, "职位管理数据");
    }

    /**
     * 获取职位管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('nmzp:job:query')")
    @GetMapping(value = "/{jobId}")
    public AjaxResult getInfo(@PathVariable("jobId") Long jobId) {
        return success(nmzpJobService.selectNmzpJobByJobId(jobId));
    }

    /**
     * 新增职位管理
     */
    @PreAuthorize("@ss.hasPermi('nmzp:job:add')")
    @Log(title = "职位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NmzpJob nmzpJob) {
        int i = nmzpJobService.insertNmzpJob(nmzpJob);
        if(i==-1){
            return AjaxResult.error("公司还未审核通过");
        }
        return toAjax(i);
    }

    /**
     * 修改职位管理
     */
    @PreAuthorize("@ss.hasPermi('nmzp:job:edit')")
    @Log(title = "职位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NmzpJob nmzpJob) {
        return toAjax(nmzpJobService.updateNmzpJob(nmzpJob));
    }

    /**
     * 删除职位管理
     */
    @PreAuthorize("@ss.hasPermi('nmzp:job:remove')")
    @Log(title = "职位管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jobIds}")
    public AjaxResult remove(@PathVariable Long[] jobIds) {
        return toAjax(nmzpJobService.deleteNmzpJobByJobIds(jobIds));
    }

    /**
     * 岗位审核
     *
     * @param nmzpJob
     * @return
     */
    @PostMapping("/examine")
    @ResponseBody
    public AjaxResult examine(@RequestBody NmzpJob nmzpJob) {
        return toAjax(nmzpJobService.examine(nmzpJob));
    }


    /**
     * 所有的岗位信息
     *
     * @param nmzpJob
     * @return
     */
    @PostMapping("/jobList")
    @ResponseBody
    public TableDataInfo jobList(NmzpJob nmzpJob) {
        startPage();
        List<NmzpJob> list = nmzpJobService.jobList(nmzpJob);
        return getDataTable(list);
    }

    /**
     * 职位搜索
     * @param nmzpJob
     * @return
     */
    @PostMapping("/jobListSerch")
    @ResponseBody
    public TableDataInfo jobListSerch( @RequestBody NmzpJob nmzpJob) {
        startPage();
        List<NmzpJob> list = nmzpJobService.jobListSerch(nmzpJob);
        return getDataTable(list);
    }


    @PostMapping("/pop")
    @ResponseBody
    public AjaxResult pop(@RequestBody NmzpJob nmzpJob) {
        String pop = nmzpJobService.pop(nmzpJob);
        return AjaxResult.success(pop);
    }

    /**
     * 岗位投递
     * @param nmzpJob
     * @return
     */
    @PostMapping("/deliver")
    @ResponseBody
    public AjaxResult deliver(@RequestBody NmzpJob nmzpJob) {
        String pop = nmzpJobService.deliver(nmzpJob);
        return AjaxResult.success(pop);
    }

    /**
     * 跟据职位id查询简历集合
     * @param nmzpJob
     * @return
     */
    @PostMapping("/jobResumeList")
    @ResponseBody
    public TableDataInfo jobResumeList(@RequestBody NmzpJob nmzpJob) {
        startPage();
        List<NmzpResume> list = nmzpJobService.jobResumeList(nmzpJob);
        return getDataTable(list);
    }



}